#!/bin/bash
set -e

API_URL="http://localhost:8888"

# 1. 创建钱包 用户1 和 用户2
curl -s -X POST $API_URL/wallets/new -H "Content-Type: application/json" -d '{"address":"用户1", "initial_balance":100}'
echo
curl -s -X POST $API_URL/wallets/new -H "Content-Type: application/json" -d '{"address":"用户2", "initial_balance":50}'
echo

# 2. 查询余额
curl -s $API_URL/wallets/用户1/balance
echo
curl -s $API_URL/wallets/用户2/balance
echo

# 3. 用户1 向 用户2 转账 30
curl -s -X POST $API_URL/transactions/new -H "Content-Type: application/json" -d '{"sender":"用户1", "recipient":"用户2", "amount":30}'
echo

# 4. 再次查询余额
curl -s $API_URL/wallets/用户1/balance
echo
curl -s $API_URL/wallets/用户2/balance
echo

# 5. 用户2 挖矿
curl -s $API_URL/mine/用户2
echo

# 6. 查询用户2余额（应增加挖矿奖励）
curl -s $API_URL/wallets/用户2/balance
echo

# 7. 查看区块链
curl -s $API_URL/chain

# 8. 查看所有钱包
curl -s $API_URL/wallets